'use strict';

const Service = require('egg').Service;

class HomeService extends Service {
  async getIndex() {
    return {
      list: [1, 2, 3, 4, 5, 6]
    }
  }
  async selectInfo(info){
    const {
      ctx,
      app
    } = this;
    const user = await app.mysql.select('user',{userName:info.userName})
    console.log(user);
    return user;
  }

  async insertUser(info) {
    console.log(info);
    let res = await this.app.mysql.insert('user', {
      userName: info.userName,
      userPwd: info.userPwd,
      salt: info.salt
    });
    console.log(res);
    return res;
  }
  async hasUser() {
    const {
      ctx,
      app
    } = this;
    const userList = await app.mysql.select('user')
    if (userList.length) {

      const user = await app.mysql.get('user', {
        userName: userName
      });
      console.log("user", user);
      if (user.length) {
        return 1;
      }
    } else {
      return 0;
    }
  }
  async getList() {
    // 仅测试用
    const {
      ctx,
      app
    } = this;
    const user = await app.mysql.select('user');
    return user;
  }
}

module.exports = HomeService;